package toy.play.ssm.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import toy.play.ssm.model.sys.SysFun;
import toy.play.ssm.model.user.User;
import toy.play.ssm.services.SysFunService;

@Controller
@RequestMapping("/sys")
public class SysFunController {

	@Autowired
	private SysFunService service;
	
		
	@RequestMapping("/showsearch")
	public String getSearchSys(HttpServletRequest request,
			HttpServletResponse response,String searchname)
			{
		ArrayList<SysFun> allsys = service.getSearchSys(searchname);
		request.setAttribute("showsysfunlist", allsys);
		return "/sys/sysindex";
			}
	
	@RequestMapping("/showall")
	public String getAllSys(HttpServletRequest request,
			HttpServletResponse response) {
			ArrayList<SysFun> allsys = service.getAllSysFun();
			request.setAttribute("showsysfunlist", allsys);
			return "/admin/success";
	}

	@RequestMapping("/fun")
	public String showAllSysFunction(HttpServletRequest request,
			HttpServletResponse response) {
			ArrayList<SysFun> allsys = service.getAllSysFun();
			request.setAttribute("showsysfunlist", allsys);
			return "sys/sysindex";
	}

	@RequestMapping("/showadd")
	public String showadd(HttpServletRequest request,
			HttpServletResponse response, String theid) {

			request.setAttribute("theid", theid);
			return "sys/add";
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request, HttpServletResponse response,
		SysFun sys) {
			service.addASysFun(sys);
			return "redirect:/sys/fun";
	}

	@RequestMapping("/showedit")
	public String showedit(HttpServletRequest request,
			HttpServletResponse response, String theid) {
			SysFun sys = service.getASysFunById(theid);
			request.setAttribute("sysfunedit", sys);
			return "sys/edit";
	}

	@RequestMapping("edit")
	public String edit(HttpServletRequest request,
			HttpServletResponse response, SysFun sys) {
			service.updateASysFun(sys);
			return "forward:/sys/fun";
	}
}
